package com.dsx.test.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author : tianwenqing
 * @version : 1.0
 * @date : 2020-11-16 18:33
 * @description :
 **/
@Slf4j
@Component
public class ShiroAuthorizationInteceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        try {
            String requestURI = request.getRequestURI();
            SecurityUtils.getSubject().checkPermission(requestURI);
        } catch (AuthorizationException e) {
            log.error("AuthorizationException", e);
            return false;

        }
        return true;
    }
}
